import request from "../../../api/request"
const state = {
    soaringList: [],
    newSongList: [],
    hotSongList: [],
    theOriginalList: [],
    listOfSinger: [],
    spliceRanklingList: []
}
const mutations = {
    GET_PLAYLIST(state, playlist) {
        let splice1 = playlist.soaringList.slice(0, 8)
        let splice2 = playlist.newSongList.slice(0, 8)
        let splice3 = playlist.hotSongList.slice(0, 8)
        let splice4 = playlist.soaringList.slice(0, 8)
        state.spliceRanklingList = []
        state.spliceRanklingList.push(splice1, splice2, splice3, splice4)
        state.soaringList = playlist.soaringList
        state.newSongList = playlist.newSongList
        state.hotSongList = playlist.hotSongList
        state.theOriginalList = playlist.theOriginalList
        state.listOfSinger = playlist.listOfSinger


    }
}
let actions = {
    // 获取官方榜单
    async getMusic() {
        let soaringList = await request({
            url: "/top/list",
            data: {
                idx: "3",
            },
            method: "get",
        })
        let newSongList = await request({
            url: "/top/list",
            data: {
                idx: "0",
            },
            method: "get",
        })
        let hotSongList = await request({
            url: "/top/list",
            data: {
                idx: "1",
            },
            method: "get",
        })
        let theOriginalList = await request({
            url: "/top/list",
            data: {
                idx: "2",
            },
            method: "get",
        })
        let listOfSinger = await request({
            url: "/toplist/artist",
            method: "get",
        })
        this.commit("GET_PLAYLIST", {
            soaringList: soaringList.playlist.tracks,
            newSongList: newSongList.playlist.tracks,
            hotSongList: hotSongList.playlist.tracks,
            theOriginalList: theOriginalList.playlist.tracks,
            listOfSinger: listOfSinger.list.artists
        })
    },
}
let getters = {
    // 获取截取的排行榜
    spliceListOfSinger: state => state.listOfSinger.slice(0, 8),
    getRanklingList: state => state.spliceRanklingList,
    // 获取完整排行榜
    getSoaringList: state => state.soaringList,
    getNewSongList: state => state.newSongList,
    getHotSongList: state => state.hotSongList,
    getTheOriginalList: state => state.theOriginalList,
    getListOfSinger: state => state.listOfSinger,
}
export default {
    state,
    mutations,
    actions,
    getters
}